home *** CD-ROM | disk | FTP | other *** search
Wrap
<?php //////////////////////////////////////////////////////////////////////////////// // <!--Copyright (c) 2006 Pure Networks Inc. All rights reserved.--> //////////////////////////////////////////////////////////////////////////////// // // Build: 3.0.6121.0 (Stable) // $Revision: #3 $ // /////////////////////////////////////////////////// // Set up some shared variables with values /////////////////////////////////////////////////// $arSharePath = ""; $arFiles = ""; $bPagination = false; $bFolderUtilsIncluded = true; /////////////////////////////////////////////////// // Function to get and validate the page number // Pages are assumed to start at 1, not 0 /////////////////////////////////////////////////// function returnPageNumber($count, $ObjectsPerPage, $sgPage) { $pageNumber = 0; if (isset($sgPage)) { $pageNumber = intval($sgPage); } if (($pageNumber < 1)) { $pageNumber = 1; } else { // we have a page number and it's above page number 1, let's make sure we're not at too high a page // if we are, we set the page number to be the max available page number if (ceil($count/$ObjectsPerPage) < $pageNumber) { $pageNumber = ceil($count/$ObjectsPerPage); } } return $pageNumber; } /////////////////////////////////////////////////// // build pagination string /////////////////////////////////////////////////// function returnPaginationString($count, $ObjectsPerPage, $iPaginationBuffer, $pageNumber) { global $bPagination, $sShare, $sPath, $iMaxPage, $sNavPage, $sQuery; $sPagination = ""; $sQuery = $_SERVER['PHP_SELF']; if (strpos($sQuery, "?") > 0) { if (strpos($sQuery, "page") > 0) { $sQsVarConcat = ""; } else { $sQsVarConcat = "&"; } } else { $sQsVarConcat = "?"; } if ($count > $ObjectsPerPage) { $bPagination = true; // What's the first page number link we display? if (($pageNumber - $iPaginationBuffer) < 1) { $iMinPage = 1; } else { $iMinPage = ($pageNumber - $iPaginationBuffer); } if (ceil($count/$ObjectsPerPage) < ($pageNumber + $iPaginationBuffer)) { $iMaxPage = ceil($count/$ObjectsPerPage); } else { $iMaxPage = ($pageNumber + $iPaginationBuffer); } $sPagination = "<br/><table class=\"PaginationTrayContain\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr>"; $sPagination .= "<td class=\"PaginationTrayLeft\"><img src=\"/images/pixel.trans.gif\" height=\"1\" width=\"1\" alt=\"\"></td>"; $sPagination .= "<td class=\"PaginationTrayDefault\"><a href=\""; $sPagination .= "javascript:gotoPage('" . $sQuery . "','1','" . ceil($count/$ObjectsPerPage) . "','" . $pageNumber . "','" . $sQsVarConcat . "');\">"; $sPagination .= "Page"; $sPagination .= "</a> "; // Do we put in the prev arrow? if ($pageNumber > 1) { $sPagination .= " <span class=\"PaginationPrev\" title=\"Previous Page\"><a href=\""; $sPagination .= $sQuery; $sPagination .= $sQsVarConcat . 'page=' . ($pageNumber - 1); $sPagination .= "\"> </a></span>"; } for($i=$iMinPage; $i<= $iMaxPage; $i++) { if ($i == $pageNumber) { $sPagination .= "<span class=\"PaginationActive\">" . $i . " </span>" . " \r\n"; } else { $sPagination .= "<a href=\"" . $sQuery . $sQsVarConcat . 'page=' . $i . "\" title=\"Go to page " . $i . "\">" . $i . "</a> \r\n"; } } // Do we put in the next arrow? if ($pageNumber < ceil($count/$ObjectsPerPage)) { $sPagination .= "<span class=\"PaginationNext\" title=\"Next Page\"><a href=\""; $sPagination .= $sQuery; $sPagination .= $sQsVarConcat . 'page=' . ($pageNumber + 1); $sPagination .= "\"> </a></span>"; } $sPagination .= "</td>"; $sPagination .= "<td class=\"PaginationTrayRight\"><img src=\"/images/pixel.trans.gif\" height=\"1\" width=\"1\" alt=\"\"></td>"; $sPagination .= "</tr></table> <!--Pagination-->"; } return $sPagination; } /////////////////////////////////////////////////// // function that prints out the no content message /////////////////////////////////////////////////// function writeNoContentMessage($bUploadEnabled, $bReadOnly, $sAccessLevel) { global $sProductNameInformal, $sParentProductNameInformal, $sNetworkName, $sNavPage, $bLoggedIn; echo ("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\" class=\"WhiteTable\">"); echo ("<tr><td id=\"Top\"><img src=\"/images/pixel.trans.gif\" width=\"1\" height=\"1\" alt=\"\"/></td></tr>"); echo ("<tr>"); echo ("<td id=\"Mid\">"); echo ("<div class=\"EmptyContianerImage\">"); echo ("<div class=\"EmptyContianerText\">"); switch ($sNavPage) { case "share": switch ($sAccessLevel) { case 0: echo ("There are no public folders available on this page."); break; case 1: case 2: echo ("There are no shared folders."); break; } break; case "folders": switch ($sAccessLevel) { case 0: case 1: case 2: echo ("There are no files in this folder."); break; } break; } echo ("</div>"); echo ("<div class=\"EmptyContianerExplain\">"); switch ($sNavPage) { case "share": if (!$bLoggedIn) { echo ("If you are the owner of this page, click the Sign In button to see your private folders."); } else { switch ($sAccessLevel) { case 0: echo ("Click \"Shared Folders\" to see your private folders."); break; case 1: case 2: echo ("Click \"Public Home Page\" to see your public folders."); break; } } break; case "folders": switch ($sAccessLevel) { case 0: echo ("If you are a visitor, return to this site later or contact a member of this network for more information."); break; case 1: case 2: if ($bUploadEnabled & !$bReadOnly) { echo ("There are currently no files in this shared folder. To add files, do one of the following depending on whether you are at home or away from home:"); echo ("<ul>"); echo ("<li>If you are at your computer, you can copy the files you want to share into this folder</li>"); echo ("<li>If you are away from home, you can upload individual files to this folder</li>"); echo ("</ul>"); } else { echo ("There are currently no files in this shared folder. To add files, copy the files you want to share into this folder."); } break; } break; } echo ("</div>"); echo ("</div>"); echo ("</td>"); echo ("</tr>"); echo ("<tr><td id=\"Bot\"><img src=\"/images/pixel.trans.gif\" width=\"1\" height=\"1\" alt=\"\"/></td></tr>"); echo ("</table>"); } function printBreadcrumbs($sShare, $sUnc, $sFolderPath, $sContainer, $iBreadCrumbTruncateLength, $objCount, $ObjectsPerPage, $sgPage, $bPersistPageNumber) { global $sNavPage, $ObjectsPerPage; /////////////////////////////////////////////////// // Generate the breadcrumb from the path // Take the folder path \\kennt\NetMagic03, this is the root of the tree // Breadcrumb should show // _My_Pictures // After that, it should show the various folder depths // _My_Pictures \ _Folder1_ \ _Folder2_ // We will generate an array with two pieces of data per entry // breadcrumb[i]['name'] // breadcrumb[i]['url'] /////////////////////////////////////////////////// /////////////////////////////////////////////////// // This is the base url, it will return the user to the first page. /////////////////////////////////////////////////// $baseUrl = '/folderview/' . $sShare . "/" . urlEncodeString($sUnc); $upFolderUrl = $baseUrl; global $bLoggedIn; if (strcmp($sFolderPath, $sUnc) == 0) { if (strlen($sContainer) < $iBreadCrumbTruncateLength) { $iRemainingChars = $iBreadCrumbTruncateLength - strlen($sContainer); } else { $iRemainingChars = 0; } $breadcrumb[] = array("name" => truncate_string($sContainer, $iBreadCrumbTruncateLength, "...", "right", true), "url" => "", "title" => $sContainer); $upFolderUrl = "/folders/"; if ($bLoggedIn) { $upFolderUrl .= "private"; } } else { $bTruncated = false; // Set truncation boolean to false as we have not yet truncated, but may along the way $remainingPath = substr($sFolderPath, strlen($sUnc) + 1); // skip past the beginning single slash $pieces = explode('\\', $remainingPath); $count = count($pieces); $iRemainingChars = round($iBreadCrumbTruncateLength,0); /////////////////////////////////////////////////// // stuff the breadcrumbs backwards (start at current folder and work backwards // towards the root shared folder) to be able to truncate on the left // Add the last piece (current folder) /////////////////////////////////////////////////// if (strlen($pieces[$count-1]) > $iBreadCrumbTruncateLength) { /////////////////////////////////////////////////// // our last piece is too long so we have to truncate already /////////////////////////////////////////////////// $breadcrumb[] = array("name" => truncate_string($pieces[$count-1], $iBreadCrumbTruncateLength, "...", "right", true), "url" => "", "title" => $pieces[$count-1]); $bTruncated = true; } else { $breadcrumb[] = array("name" => $pieces[$count-1], "url" => "", "title" => $pieces[$count-1]); $iRemainingChars = $iRemainingChars - strlen($pieces[$count-1]); } if (!$bTruncated) { /////////////////////////////////////////////////// // Add all items as urls except for the very last one (current folder) /////////////////////////////////////////////////// $i=($count)-2; for ($i=($count)-2; $i>=0; $i--) { $url = $baseUrl; $iRemainingChars = $iRemainingChars - strlen($pieces[$i]); /////////////////////////////////////////////////// // iterate through the items forwards (from the shared folder root to the current // folder) to create the path for the href for this item /////////////////////////////////////////////////// $j=0; for ($j=0;$j<=$i;$j++) { $url .= urlEncodeString("\\" . $pieces[$j]); } if ($i == ($count - 2 )) { $upFolderUrl = $url; // let's get the url for the parent folder setup here if ($bPersistPageNumber) { $upFolderUrl .= "?page=" . returnPageNumber($objCount, $ObjectsPerPage, $sgPage); } } if ($iRemainingChars >= 0) { $breadcrumb[] = array("name" => $pieces[$i], "url" => $url, "title" => $pieces[$i]); } else { $bTruncated = true; $breadcrumb[] = array("name" => truncate_string($pieces[$i], $iRemainingChars, "...", "right", true), "url" => $url, "title" => $pieces[$i]); /////////////////////////////////////////////////// // we've truncated, let's break out & adjust the remaining chars /////////////////////////////////////////////////// $iRemainingChars = $iRemainingChars - strlen($pieces[$i]); break; } } } /////////////////////////////////////////////////// // Add the shared folder root of the path if there's room for it. /////////////////////////////////////////////////// if ($iRemainingChars > 0) { if ($bPersistPageNumber) { $baseUrl .= "?page=" . returnPageNumber($objCount, $ObjectsPerPage, $sgPage); } if (strlen($sContainer) > $iRemainingChars) { // not enough chars, let's truncate the root string... $breadcrumb[] = array("name" => truncate_string($sContainer, $iRemainingChars, "...", "right", true), "url" => $baseUrl, "title" => $sContainer); } else { $breadcrumb[] = array("name" => $sContainer, "url" => $baseUrl, "title" => $sContainer); } } } /////////////////////////////////////////////////// //got the info we need, let's start writing it... /////////////////////////////////////////////////// $iBreadcrumbChars = 0; echo "<td class=\"ContentTableTM1\">"; echo "<span class=\"ParentUpFolder\""; echo "onMouseOver=\"this.className='ParentUpFolderOver'\" onMouseOut=\"this.className='ParentUpFolder'\">"; echo "<a href=\"" . $upFolderUrl . "\" title=\"Go up to the next folder\">"; echo "<img src=\"/images/pixel.trans.gif\" alt=\"Go up to the next folder\" border=\"0\"/></a></span></td>"; echo "<td class=\"ContentTableTM2\">"; echo "<span class=\"Breadcrumbs\">"; if ($bLoggedIn) { echo ("<a href=\"/folders/private\" title=\"Go to shared folders.\">Home Page</a> \\ "); } else { echo ("<a href=\"/folders/public\" title=\"Go to shared folders.\">Home Page</a> \\ "); } for ($k=(count($breadcrumb)); $k>0; $k--) { $crumb = $breadcrumb[$k-1]; if ($crumb['url'] != "") { print "<a href=\"" . htmlentities($crumb['url']) . "\" title=\"Go to " . htmlentities($crumb['title']) . "\">" . str_replace(" ", " ",htmlentities($crumb['name'])) . "</a> \\ "; } else { print "<strong>" . str_replace(" ", " ",htmlentities($crumb['name'])) . "</strong>"; } } echo "</span></td>"; } // -- breadcrumb function end -- function removeSharesFromArray($arArray, $iType) { $iShareArrayCounter = 0; try { foreach ($arArray as $share) { if ($share->AccessLevel != intval($iType)) { $arAvailableShares[$iShareArrayCounter] = $share; } $iShareArrayCounter++; } return $arAvailableShares; } catch (exception $ex) { return null; } } function createSessionFileArrays($sShare, $sPath, $sFolderPath, $nmSharedPlace, $bSamePageReset, $sgPage) { global $arSharePath, $arFiles, $ObjectsPerPage, $bPlaylistLinkEnabled; // Let's see if this folder is cached in the session, if it is, we use it to display // folders and files, otherwise, we build one up, stick IT in the session, and then use it // we compare an array that may be in the session with the current share/path to see if the // folder in the session (if there is one) corresponds to teh current share/path. // $arSharePath contains this info on the current share/path combination // $arSharePath[0] = $sShare // $arSharePath[1] = $sPath // $arSharePath[2] = $sLastFileType - used to switch between UI styles for folders vs photos vs non photos // $arSharePath[3] = $bSlideShowLinkEnabled - do we have any pictures at all here - if so we display the slideshow link // $arSharePath[4] = $pageNumber - this is the page number we last requested $bReadFolderFromFS = true; if (isset($_SESSION['currentFolderInfo'])) { $arSharePath = $_SESSION['currentFolderInfo']; if ($arSharePath[0] == $sShare && $arSharePath[1] == $sPath) { // our session folder object is for the current share/path combination if (returnPageNumber(count($_SESSION['currentFolderFiles']),$ObjectsPerPage, $sgPage) == $_SESSION['currentFolderInfo'][4]) { if ($bSamePageReset) { //we're asking for the same page, let's unset the cache unset($_SESSION['currentFolderInfo']); unset($_SESSION['currentFolderFiles']); } else { // we're just viewing images, let's not unset or readfrom fs $bReadFolderFromFS = false; } } else { // no need to re-read from the FS $bReadFolderFromFS = false; //set new get request page number $_SESSION['currentFolderInfo'][4] = returnPageNumber(count($_SESSION['currentFolderFiles']),$ObjectsPerPage, $sgPage); $arSharePath = $_SESSION['currentFolderInfo']; $arFiles = $_SESSION['currentFolderFiles']; } } else { // they differ, let's unset the session vars so they can get set properly below unset($_SESSION['currentFolderInfo']); unset($_SESSION['currentFolderFiles']); } } /////////////////////////////////////////////////// // 1) we have no file info array in session, let's build it // 2) the array we have in session does not match current /////////////////////////////////////////////////// if ($bReadFolderFromFS) { /////////////////////////////////////////////////// // LEGENDS: // // (file types) legend // // we store the filetype in the [1] position of the various arrays so that we can split the displayed listings into sections // // 0 -- folder // // 1 -- picture // // 2 -- non picture file // // $arFolder folders, $arPhotos photo, and $arFiles non photo files arrays // // [$cFiles][0] - folder name/file name // // [$cFiles][1] - item type - see seperate legend above // NOTE ON ABOVE ARRAYS: // Since we want to display folders first, and then photos, and then files, we need to put these differing // 'file' types into separate arrays until the end, where we slap the arrays together in the right order // we don't know due to alpha order from teh filesystem where we'll find any of the mentioned item types, // they'll be mixed /////////////////////////////////////////////////// /////////////////////////////////////////////////// // initalize some variables /////////////////////////////////////////////////// $arSharePath[0] = $sShare; // share info to compare to session based array on future visits $arSharePath[1] = $sPath; // path info to compare to session based array on future visits $cFiles = 0; // keeps count of which array element to define the information in $arFiles = null; // array for all files - we use this at the end $arFilesPhotos = null; // array for photo files $arFilesFiles = null; // array for non photo files $arFolder = null; // array for folders $bSlideShowLinkEnabled = false; // we won't show this unless we need to /////////////////////////////////////////////////// // let's open up the folder on the FS & feed our arrays /////////////////////////////////////////////////// if (opendir($sFolderPath) !== false) { $handle = opendir($sFolderPath); } else { $arFolder[$cFiles][0] = "badperms"; $arFolder[$cFiles][1] = "3"; // per (file types) legend 3 = error } while (false !== ($file = readdir($handle))) { $sFullPath = $sFolderPath . "\\" . $file; // we've got a directory, make sure it's not the . or .. folder and stuff it's info in the folder array if ($nmSharedPlace->IsDisplayableItem($sFullPath) && is_dir($sFullPath) && ($file != ".") && ($file != "..")) { $arFolder[$cFiles][0] = $file; $arFolder[$cFiles][1] = "0"; // per (file types) legend 0 = folder } // we've got a file, let's grab the extension and stuff it's info in either the photo or the non photo array if (is_file($sFullPath) && is_readable($sFullPath) && $nmSharedPlace->IsDisplayableItem($sFullPath)) { $sFullFilePath = $sFolderPath . "\\" . $file; $fileExtension = strtolower(strrchr($file, ".")); switch ($fileExtension) { case ".n2g": // our special little files, let's not show them... // TODO - make them system files when saving?? break; case ".mp3": case ".wma": $bPlaylistLinkEnabled = true; $arFilesFiles[$cFiles][0] = urlEncodeString($file); $arFilesFiles[$cFiles][1] = "2"; // per (file types) legend 2 = non photo file break; case ".jpg": case ".jpe": case ".jpeg": case ".jfif": case ".gif": case ".png": $bSlideShowLinkEnabled = true; // we've got at least one slideshow capable file, let's display the link $arFilesPhotos[$cFiles][0] = urlEncodeString($file); $arFilesPhotos[$cFiles][1] = "1"; // per (file types) legend 1 = photo file break; case ".bmp": case ".dib": case ".ico": case ".tif": case ".tiff": $arFilesPhotos[$cFiles][0] = urlEncodeString($file); $arFilesPhotos[$cFiles][1] = "1"; // per (file types) legend 1 = photo file break; default: $arFilesFiles[$cFiles][0] = urlEncodeString($file); $arFilesFiles[$cFiles][1] = "2"; // per (file types) legend 2 = non photo file } } $cFiles++; // increment the array position counter } /////////////////////////////////////////////////// // Let's create the final folder/file array list in this order: // 1) folder array if it exists // 2) photo files array if it exists // 3) non photot files array if it exists // NOTE: we prepend these to each other in reverse order /////////////////////////////////////////////////// if (isset($arFilesPhotos) && isset($arFilesFiles)) { $arFilesFiles = returnNatsortedArrayOnIndex($arFilesFiles,0); $arFilesPhotos = returnNatsortedArrayOnIndex($arFilesPhotos,0); $arFiles = $arFilesPhotos + $arFilesFiles; } else { if (!isset($arFilesPhotos)) { $arFilesFiles = returnNatsortedArrayOnIndex($arFilesFiles,0); $arFiles = $arFilesFiles; } else { $arFilesPhotos = returnNatsortedArrayOnIndex($arFilesPhotos,0); $arFiles = $arFilesPhotos; } } if (isset($arFolder) && isset($arFiles)) { $arFolder = returnNatsortedArrayOnIndex($arFolder,0); $arFiles = $arFolder + $arFiles; } else { if (!isset($arFiles)) { $arFolder = returnNatsortedArrayOnIndex($arFolder,0); $arFiles = $arFolder; } } /////////////////////////////////////////////////// // stuff now defined variables into the arrays /////////////////////////////////////////////////// $arSharePath[3] = $bSlideShowLinkEnabled; $arSharePath[4] = returnPageNumber(count($arFiles),$ObjectsPerPage, $sgPage); // the page number $arSharePath[5] = $bPlaylistLinkEnabled; /////////////////////////////////////////////////// // stuff the arrays in the session for reuse while paging through the folder /////////////////////////////////////////////////// $_SESSION['currentFolderFiles'] = $arFiles; $_SESSION['currentFolderInfo'] = $arSharePath; } $arSharePath = $_SESSION['currentFolderInfo']; $arFiles = $_SESSION['currentFolderFiles']; } function getFolderName($nmSharedPlace, $sPath) { // normally we could just do a basename on the path to get the folder name // however, when the folder name is the share name, it is not the friendly share name $sShareName = getShareTitle ($nmSharedPlace); if (isset($sShareName) && (("\\" . basename($sPath)) == strrchr($nmSharedPlace->Unc, "\\"))) { $sFolderName = $sShareName; } else { $sFolderName = basename($sPath); } $iUncLocationLength = strlen($nmSharedPlace->Location); if ($sFolderName == substr(stripslashes($nmSharedPlace->Unc), $iUncLocationLength + 1)) { // we've got the truncated share name here (os level one), let's get a better name for it $sFolderName = $nmSharedPlace->ShareName; } return $sFolderName; } function getShareTitle ($nmSharedPlace) { $sShareName = $nmSharedPlace->ShareName; $sFriendlyName = $nmSharedPlace->FriendlyName; $sAccessLevel = $nmSharedPlace->AccessLevel; if (isValidString($sFriendlyName) && $sAccessLevel == 0) { return $sFriendlyName; } else { return $sShareName; } } function isSupportedDownloadExtension($sDownloadUnsupportedExtensions, $sFileExtension) { if (isValidString($sFileExtension)) { if (strpos($sDownloadUnsupportedExtensions, strtolower($sFileExtension)) === false) { return true; } else { return false; } } } function returnNatsortedArrayOnIndex( &$arArray, $index = null, $bCaseInsensitive = true ) { // init array vars needed $arTemp = array(); $arReturn = array(); // create a temp array with the key to be natsorted foreach ( $arArray as $key=>$value ) { reset($value); $arTemp[$key] = is_null($index) ? current($value) : $value[$index]; } // natcasesort the temp array on the desired key now stored in it if ($bCaseInsensitive) { natcasesort($arTemp); } else { natsort($arTemp); } // create a return array that matches the key order of the input array, but sorted as per teh temp array foreach ( $arTemp as $key=>$value ) { $arReturn[$key] = $arArray[$key]; } // return the array return $arReturn; } ?>